import QtQuick 2.15
import QtQml.Models 2.15
import org.ukui.systemTray 1.0
import org.ukui.quick.items 1.0
import org.ukui.quick.views 1.0
import org.ukui.quick.types 1.0

Item {
    id: dropArea
    property string trayGroups: ""
    property var trayIcon
    property int order
    signal dragFinshed()
    signal dragStart(int index)

    width: 40
    height: 40

    MouseArea {
        id: mouseArea
        anchors.fill: parent
        drag.target: icon
        drag.onActiveChanged: {
            if (drag.active) {
                dropArea.dragStart(icon.draggableOrder);
            } else {
                dropArea.dragFinshed();
            }
        }

        onPressed: {
            icon.grabToImage(function(result) {
                icon.Drag.imageSource = result.url
                return result;
            })
        }
    }
    Icon {
        id: icon
        property int draggableOrder: order

        Drag.active: mouseArea.drag.active
        Drag.supportedActions: Qt.CopyAction
        Drag.dragType: Drag.Automatic
        Drag.hotSpot.x: icon.width / 2
        Drag.hotSpot.y: icon.height / 2
        Drag.mimeData: {"groups": trayGroups}

        width: 40
        height: 40
        source: trayIcon
    }

}
